package cn.tx.dao.impl;

import org.apache.commons.lang.StringUtils;

import cn.tx.dao.RoleDao;
import cn.tx.model.Role;
import cn.tx.query.RoleQuery;

public class RoleDaoImpl extends BaseDaoImpl<Role, RoleQuery> implements RoleDao {

	@Override
	public String createHql(RoleQuery q) {
		String hql = "from Role e where 1=1 ";
		String condition = this.createConditionHql(q);
		hql = hql + condition + "order by e.roleId desc";
		return hql;
	}
 
	@Override
	public String createHqlCount(RoleQuery q) {
		String hql = "select count(e) from Role e where 1=1 ";
		//StringUtils.isNotBlank判断当前的字符串是不是空串和null
		String condition = this.createConditionHql(q);
		hql = hql + condition;
		return hql;
	}

	@Override
	public String createConditionHql(RoleQuery q) {
		String hql = "";
		if(StringUtils.isNotBlank(q.getName())){
			hql = hql + "and e.name like :name ";
		}
		if(StringUtils.isNotBlank(q.getCode())){
			hql = hql + "and e.code like :code ";
		}
		
		return hql;
	}



}
